﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;

namespace Zhj.Community.WebApp
{
    public class AutoFacConfig
    {
        public static void Register()
        {
            ContainerBuilder builder = new ContainerBuilder();

            Assembly controllerAss = Assembly.Load("Zhj.Community.WebApp");
            builder.RegisterControllers(controllerAss);

            Assembly application = Assembly.Load("Zhj.Community.Application");
            Type[] atypes = application.GetTypes();
            builder.RegisterTypes(atypes)
                .AsImplementedInterfaces();

            Assembly repositoryAss = Assembly.Load("Zhj.Community.Domain");
            Type[] rtypes = repositoryAss.GetTypes();
            builder.RegisterTypes(rtypes)
                .AsImplementedInterfaces();

            Assembly servicesAss = Assembly.Load("Zhj.Community.Repository");

            Type[] stypes = servicesAss.GetTypes();
            builder.RegisterTypes(stypes)
                .AsImplementedInterfaces();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

        }

    }
}